package com.deliveryservicesystem.app.validation;

import com.jgoodies.binding.value.AbstractValueModel;
import com.jgoodies.common.base.Strings;
import com.jgoodies.validation.ValidationResult;
import com.jgoodies.validation.Validator;

/**
 * File Name: CustomerValidator.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.presentation.desktop.addpanel
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
public class CustomerValidator extends AbstractValueModel implements Validator<ValidationResult>
{

    private static final long serialVersionUID = 1L;
    private String txtAddress;
    private String txtContactNo;
    private String txtFName;
    private String txtLName;

    public CustomerValidator(String txtAddress, String txtContactNo, String txtFName, String txtLName)
    {
        this.txtAddress = txtAddress;
        this.txtContactNo = txtContactNo;
        this.txtFName = txtFName;
        this.txtLName = txtLName;
    }

    public String getTxtAddress()
    {
        return txtAddress;
    }

    public void setTxtAddress(String txtAddress)
    {
        this.txtAddress = txtAddress;
    }

    public String getTxtContactNo()
    {
        return txtContactNo;
    }

    public void setTxtContactNo(String txtContactNo)
    {
        this.txtContactNo = txtContactNo;
    }

    public String getTxtFName()
    {
        return txtFName;
    }

    public void setTxtFName(String txtFName)
    {
        this.txtFName = txtFName;
    }

    public String getTxtLName()
    {
        return txtLName;
    }

    public void setTxtLName(String txtLName)
    {
        this.txtLName = txtLName;
    }

    @Override
    public Object getValue()
    {
        return this;
    }

    @Override
    public void setValue(Object newValue)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ValidationResult validate(ValidationResult validationTarget)
    {

        if (Strings.isEmpty(txtFName.trim()))
        {
            validationTarget.addError("First name required");
        }
        if (Strings.isEmpty(txtLName.trim()))
        {
            validationTarget.addError("Last name required");
        }
        if (Strings.isEmpty(txtContactNo.trim()))
        {
            validationTarget.addError("Contact number required");
        }
        if (Strings.isEmpty(txtAddress.trim()))
        {
            validationTarget.addError("Address required");
        }

        return validationTarget;
    }
}
